<?php

use App\Http\Controllers\Assets\ExpensesController;
use App\Http\Controllers\Assets\RevenuesController;
use App\Http\Controllers\FeedbackController;
use App\Http\Controllers\User\BecomeDueController;
use App\Http\Controllers\User\WeightManagementController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;

// 认证相关路由（无需认证）
Route::prefix('auth')->group(function () {
    Route::post('register', [AuthController::class, 'register']);
    Route::post('login', [AuthController::class, 'login']);
});

// 需要认证的路由
Route::middleware('jwt.custom')->group(function () {
    // 用户信息相关
    Route::prefix('auth')->group(function () {
        Route::get('me', [AuthController::class, 'me']);
        Route::post('refresh', [AuthController::class, 'refresh']);
        Route::post('logout', [AuthController::class, 'logout']);
        Route::post('changePassword', [AuthController::class, 'changePassword']);
        Route::post('updateProfile', [AuthController::class, 'updateProfile']);

        // 签到
        Route::post('checkIn', [AuthController::class, 'checkIn']);
        // 获取用户签到信息
        Route::post('getCheckInInfo', [AuthController::class, 'getCheckInInfo']);
    });

    Route::prefix('assets')->group(function () {
        Route::prefix('portfolio')->group(function () {
            // 投资组合概览
            Route::get('overview', [RevenuesController::class, 'overview']);
            // 投资组合概览
            Route::post('updateTotalAmount', [RevenuesController::class, 'updateTotalAmount']);
            // 收益趋势
            Route::get('revenueTrend', [RevenuesController::class, 'revenueTrend']);
            // 添加收益
            Route::post('revenueAdd', [RevenuesController::class, 'revenueAdd']);
        });

        // 支出趋势
        Route::get('expensesTrend', [ExpensesController::class, 'expensesTrend']);
        // 添加支出
        Route::post('expensesAdd', [ExpensesController::class, 'expensesAdd']);


        /*
         * 微信小程序
         */
        // 账单列表
        Route::get('accounting', [ExpensesController::class, 'accounting']);
        // 添加账单
        Route::post('accounting', [ExpensesController::class, 'addAccounting']);
        // 退款
        Route::put('accounting/{id}', [ExpensesController::class, 'refund'])->where('id', '[0-9]+');
        // 删除订单
        Route::delete('accounting/{id}', [ExpensesController::class, 'delete'])->where('id', '[0-9]+');

    });

    // 到期提醒
    Route::prefix('due')->group(function () {
        Route::get('list', [BecomeDueController::class, 'list']);
    });


    // 其他需要认证的API
    Route::get('/user', function (Request $request) {
        return $request->user();
    });


    // 体重管理
    Route::prefix('weight')->group(function () {
        // 设置身高与理想体重
        Route::post('setInfo', [WeightManagementController::class, 'setInfo']);
        // 获取体重记录列表
        Route::get('records', [WeightManagementController::class, 'list']);
        // 创建体重记录
        Route::post('records', [WeightManagementController::class, 'add']);
        // 获取体重统计信息
        Route::get('stats', [WeightManagementController::class, 'stats']);
        // 设置目标体重
        Route::post('target', [WeightManagementController::class, 'target']);
        // 设置身高
        Route::post('height', [WeightManagementController::class, 'setHeight']);
        // 获取身高
        Route::get('height', [WeightManagementController::class, 'getHeight']);
    });


    // 问题反馈
    Route::post('feedback', [FeedbackController::class, 'feedback']);


});

// 成就列表
Route::get('achievement', [AuthController::class, 'achievement']);

Route::get('test', function (Request $request) {
    return (object)['response' => 'ok'];
});

